﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using BDD.TicTacToe.Domain;
using BDD.TicTacToe.Ui.Mvc.Models;

namespace BDD.TicTacToe.Ui.Mvc.Controllers
{
    public class MenuController : Controller
    {
        private readonly IGameRepository _gameRepository;

        public MenuController(IGameRepository gameRepository)
        {
            _gameRepository = gameRepository;            
        }

        //
        // GET: /TicTacToe/

        public ActionResult Index()
        {
            return View(new NewGameViewModel());
        }


        //
        // POST: /TicTacToe/
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Index(NewGameViewModel newGame)
        {
            var game = new Game(newGame.PlayerXName, newGame.PlayerOName);

            _gameRepository.Add(game);

            return RedirectToAction("Display", "GamePlay", new { gameId = game.Id.ToString() });
        }
    }
}
